package com.zxx.controller;

import com.zxx.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    @RequestMapping("/hello")
    public String hello(Model model,String id) {
        model.addAttribute("hello", "hello world!");
        System.out.println("接收到前台的值："+id);

        ArrayList<User> users = new ArrayList<>();
        users.add(new User(1,"小明",18));
        users.add(new User(2,"小红",28));
        users.add(new User(3,"小强",38));
        model.addAttribute("users",users);

        HashMap<String, Object> map = new HashMap<>();
        map.put("no",123);
        map.put("address","深圳");
        model.addAttribute("map",map);

        String[] names = {"张三","李四","王五"};
        model.addAttribute("names",names);

        model.addAttribute("now",new Date());

        model.addAttribute("age",22);

        return "demo";
    }
}
